package com.mall.b2c.plugin.search;

import com.mall.b2c.domain.goods.GoodsCategoryDomain;
import com.mall.common.hibernate.Finder;
import com.mall.common.plugin.AutoRegisterPlugin;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

/**
 * Created by Misun on 2017/2/11.
 */
public class StoreSearchFilter extends AutoRegisterPlugin implements IGoodsSearchFilter{

    @Override
    public void filter(Finder finder, GoodsCategoryDomain cat, String urlFragment) {
        if(StringUtils.isNotBlank(urlFragment) && Pattern.matches("^\\d+$", urlFragment)) {
            Long storeId = Long.valueOf(urlFragment);
            finder.append(" and g.store.id = :storeId");
            finder.setParam("brandId", storeId);
        }
    }

    @Override
    public List<SearchSelector> createSelectorList(GoodsCategoryDomain cat, String url, String urlFragment, Map<String, String> paramMap, String hql, Finder finder) {
        List<SearchSelector> searchSelectors = new ArrayList<SearchSelector>();
        return searchSelectors;
    }


    @Override
    public String getFilterId() {
        return "store";
    }

    @Override
    public String getSysId() {
        return "storeList";
    }

    @Override
    public String getType() {
        return "goodsSearchFilter";
    }

    @Override
    public String getId() {
        return "storeSearchFilter";
    }

    @Override
    public String getName() {
        return "门店筛选器";
    }

    @Override
    public String getVersion() {
        return "1.0";
    }

    @Override
    public String getAuthor() {
        return "liuzx";
    }

    @Override
    public void perform(Object... params) {

    }

    @Override
    public void register() {

    }
}
